<?php

namespace app\admin\model\cms;

use think\Model;

//IM聊天群组用户与与用户中间表
class UserChatGroupUsersModel extends Model
{

    

    

    // 表名
    protected $table = 'user_chat_group_users';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_mute_text'
    ];
    

    
    public function getIsMuteList()
    {
        return ['0' => __('否'), '1' => __('是')];
    }


    public function getIsMuteTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_mute']) ? $data['is_mute'] : '');
        $list = $this->getIsMuteList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    //一对一关联用户
    public function user()
    {
        return $this->hasOne("app\common\model\User", "id","user_id")->field('id,nickname,avatar,bio,email');
    }

    //
    public function chatGroup()
    {
        return $this->hasOne(UserChatGroupsModel::class, "id","chat_group_id")->field('id,name');
    }






}
